package com.snopy.designPattern.structure.proxy;


import com.snopy.designPattern.structure.proxy.impl.ThirdPartyYouTubeClass;
import com.snopy.designPattern.structure.proxy.impl.YouTubeCacheProxy;
import lombok.extern.slf4j.Slf4j;

/**
 * @author snopy
 * @version 1.0.0
 * @classname ProxyPatternDemo
 * @description
 * @email 77912204@qq.com
 * @date 2022/03/03 18:53
 */
@Slf4j
public class ProxyPatternDemo {
    public static void main(String[] args) {
  /*      Image image = new ProxyImage();
        image.display();*/
        YouTubeDownloader naiveDownloader = new YouTubeDownloader(new ThirdPartyYouTubeClass());
        YouTubeDownloader smartDownLoader = new YouTubeDownloader(new YouTubeCacheProxy());
        long naive = test(naiveDownloader);
        long smart = test(smartDownLoader);
        log.info("Time saved by caching proxy:{} ms",smart-naive);

    }
    private static long test(YouTubeDownloader downloader){
        long startTime = System.currentTimeMillis();
        downloader.renderPopularVideos();
        downloader.renderVideoPage("catzzzzzzzzzzzz");
        downloader.renderPopularVideos();
        downloader.renderVideoPage("dancesvideoo");
        downloader.renderVideoPage("catzzzzzzzzzzzzz");
        downloader.renderVideoPage("somethervid");
        long estimatedTime = System.currentTimeMillis() - startTime;
        log.info("Time elapsed: {}ms\n",estimatedTime);
        return estimatedTime;
    }
}
